/**
 * @author Justin Akin
 * @version Action Pals Core Library 0.1.0
 */
package com.actionpals.components.controls
{	
	import flash.media.Camera;	
	
	/**
	 * 
	 */
	public class CameraVideo extends SimpleVideo
	{
		
	//--------------------------------------------------------------------------------
	//
	//	Protected Member Variables
	//
	//--------------------------------------------------------------------------------
	
		protected var _camera:Camera;
		
	//--------------------------------------------------------------------------------
	//
	//	Constructor
	//
	//--------------------------------------------------------------------------------
		
		/**
		 * Constructor
		 */
		public function CameraVideo( width:int=320, height:int=240 )
		{
			super( width, height );
		}
		
	//--------------------------------------------------------------------------------
	//
	//	Getters and Setters
	//
	//--------------------------------------------------------------------------------
		 
		/**
		 *  A numeric value that specifies the amount of motion the camera is detecting.
		 */
		public function get activityLevel():Number
		{
			return _camera.activityLevel;
		}
		
		/**
		 * An integer that specifies the maximum amount of bandwidth the current
		 * outgoing video feed can use, in bytes.
		 */
		public function get bandwidth():int
		{
			return _camera.bandwidth;
		}
		
		/**
		 * The rate at which the camera is capturing data, in frames per second.
		 */
		public function get currentFPS():Number
		{
			return _camera.currentFPS;
		}
		
		/**
		 * The maximum rate at which you want the camera to capture data, in
		 * frames per second.
		 */
		public function get fps():Number
		{
			return _camera.fps;
		}
		
		/**
		 * The current capture height, in pixels.
		 */
		public function get captureHeight():int
		{
			return _camera.height;
		}
		
		/**
		 * A zero-based integer that specifies the index of the camera, as reflected
		 * in the array returned by the names property.
		 */
		public function get index():int
		{
			return _camera.index;
		}
		
		/**
		 * Specifies which video frames are transmitted in full ( called keyframes )
		 * instead of being interpolated by the video compression algorithm.
		 */
		public function get keyFrameInterval():int
		{
			return _camera.keyFrameInterval;
		}
		
		/**
		 * Specifies which video frames are transmitted in full ( called keyframes )
		 * instead of being interpolated by the video compression algorithm.
		 */
		public function set keyFrameInterval( keyFrameInterval:int ):void
		{
			_camera.setKeyFrameInterval( keyFrameInterval );
		}
		
		/**
		 * Specifies whether a local view of what the camera is capturing is
		 * compressed and decompressed ( true ), as it would be for live transmission
		 * using Flash Media Server, or uncompressed ( false ).
		 */
		public function getLoopback():Boolean
		{
			return _camera.loopback;
		}
		
		/**
		 * Specifies whether to use a compressed video stream for a local view of the camera.
		 */
		public function setLoopback( compress:Boolean = false ):void
		{
			_camera.setLoopback( compress );
		}
		
		/**
		 * Sets the camera capture mode to the native mode that best meets the
		 * specified requirements.
		 */
		public function setMode( width:int, height:int, fps:Number, favorArea:Boolean = true ):void
		{
			_camera.setMode( width, height, fps, favorArea );
		}
		
		/**
		 * A numeric value that specifies the amount of motion required to invoke the
		 * activity event.
		 */
		public function getMotionLevel():int
		{
			return _camera.motionLevel;
		}
		
		/**
		 * Specifies how much motion is required to dispatch the activity event.
		 */
		public function setMotionLevel( motionLevel:int, timeout:int = 2000 ):void
		{
			_camera.setMotionLevel( motionLevel, timeout );
		}
		
		/**
		 * The number of milliseconds between the time the camera stops detecting
		 * motion and the time the activity event is invoked.
		 */
		public function get motionTimeout():int
		{
			return _camera.motionTimeout;
		}
		
		/**
		 * A Boolean value that specifies whether the user has denied access to the
		 * camera ( true ) or allowed access ( false ) in the Flash Player Privacy panel.
		 */
		public function get muted():Boolean
		{
			return _camera.muted;
		}
		
		/** 
		 * A string that specifies the name of the current camera, as returned by
		 * the camera hardware.
		 */		
		public function get cameraName():String
		{
			return _camera.name;
		}
		
		/**
		 * An integer specifying the required level of picture quality, as determined 
		 * by the amount of compression being applied to each video frame.
		 */
		public function getQuality():int
		{
			return _camera.quality;
		}

		/**
		 * Sets the maximum amount of bandwidth per second or the required picture
		 * quality of the current outgoing video feed.
		 */
		public function setQuality( bandwidth:int, quality:int ):void
		{
			_camera.setQuality( bandwidth, quality );
		}
		
		/**
		 *  The current capture width, in pixels.
		 */
		public function get captureWidth():int{
			return _camera.width;
		}
		
	//--------------------------------------------------------------------------------
	//
	//	Protected Methods
	//
	//--------------------------------------------------------------------------------
 	 			
		protected override function init( width:int, height:int ):void
		{	
			super.init( width, height );	
			_camera = Camera.getCamera();
		}
	}	
}